/* 
 * File:   HostInfo.h
 * Author: Bram
 *
 * Created on January 9, 2013, 2:42 PM
 */

#ifndef HOSTINFO_H
#define	HOSTINFO_H

const int MSG_HEADER_LEN = 6;

const int MAX_RECV_LEN = 8096;
const int MAX_MSG_LEN = 1024;
const int PORTNUM = 1301;

//deze word als 1e overal, gebruikt, detecteert hier of het window of linux is
#if defined __CYGWIN32__
	#define _OS_WIN
#else
	#define _OS_OTHER
#endif

#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>

#include <stdio.h>
#include <stdlib.h>

#include "logger.h"
#include "Utility.h"

enum hostType {NAME, ADDRESS};
const int HOST_NAME_LENGTH = 64;

class HostInfo {
public:
    HostInfo();
    // Retrieves the host entry based on the host name or address
    HostInfo(const std::string& hostName, hostType type);
    
    HostInfo(const HostInfo& orig);
    virtual ~HostInfo();
    
    // Retrieves the hosts IP address
    char* getHostIPAddress() 
    {
        struct in_addr *addr_ptr;
		// the first address in the list of host addresses
        addr_ptr = (struct in_addr *)*hostPtr->h_addr_list;
		// changed the address format to the Internet address in standard dot notation
        return inet_ntoa(*addr_ptr);
    }    
    
    // Retrieves the hosts name
    char* getHostName()
    {
        return const_cast<char*>(hostPtr->h_name);
    }

    // Opens the host entry database
    void openHostDb()
    {
            endhostent();
            searchHostDB = 1;
            sethostent(1);
            char hostname[255] = "";
            gethostname(hostname,sizeof(hostname));
            hostPtr = gethostbyname(hostname);
    }
private:
    char searchHostDB;     // search the host database flag
    struct hostent *hostPtr;    // Entry within the host address database

};

#endif	/* HOSTINFO_H */

